"""
@name : 12-10 面向对象
@author : hj
@projectname: CJH
"""


# # 使用类实现迭代器
# class Iterator1():
#     def __init__(self, it):
#         self.index = 0
#         self.it = it
#
#     def __iter__(self):
#         return self
#
#     def __next__(self):
#         if self.index >= len(self.it):
#             print("迭代结束")
#         else:
#             self.index += 1
#             return self.it[self.index - 1]
#
#
# lst = [1, 2, 3, 4, 5, 6]
# str1 = "abcdef"
# itera = Iterator1(str1)
# print(itera.__next__())
# print(itera.__next__())
# print(itera.__next__())
# print(itera.__next__())
# print(itera.__next__())
# print(itera.__next__())
# print(itera.__next__())
# print(itera.__next__())


# 实现斐波拉契数列
# class Fibonacci():
#     def __init__(self):
#         self.a = 0
#         self.b = 1
#
#     def __iter__(self):
#         return self
#
#     def __next__(self):
#         self.a, self.b = self.b, self.a + self.b
#         return self.a
#
#
# f = Fibonacci()
# for i in range(9):
#     print(f.__next__(), end=' ')

# 使用面向对象做一个ATM（存取款功能）
# ATM类
#  没写完，待完善
# class ATM():
#     #  属性： 钱，区域
#     money = 1000
#     area = '长沙'
#     #  属性：用户名，  密码， 账户金额
#     dict1 = {"root": {'passwd': 123456, 'yue': 1000}, "hejin": {'passwd': 123456, 'yue': 6000}}
#
#     def __init__(self, account, password, sum1):
#         self.account = account
#         self.password = password
#         self.sum1 = sum1
#         if self.account in self.dict1:
#             print('用户存在，无需开户')
#         else:
#             self.dict1[account] = {'passwd': password, 'yue': sum1}
#             print(f"开户成功！当前余额为：{self.sum1}")
#
#     #  方法：（存取）
#     def draw_money(self, getmoney):
#         if getmoney <= self.money:
#             self.money -= getmoney
#             print(f"取了{getmoney},还剩余{self.money}")
#         else:
#             print("atm余额不足")
#
#     def store_money(self, putmoney):
#         self.money += putmoney
#         print(f"已存{putmoney}，余额为：")
#
#
# #      取了钱ATM的钱就会减少
# #      用户的账户的钱也会减少
# # 主界面
# print("********** Welcome to ATM **********")
# while True:
#     print("1：开户\n2：存款\n3：取款\n4：退出")
#     option = input("请输入你的选择：")
#     if option.isdigit():
#         option = int(option)
#         if option == 1:
#             user = input("请输入你的开户账号：")
#             pd = input("请输入你的初始密码：")
#             initial_money = int(input("请输入你的初始金额："))
#             a = ATM(user, pd, initial_money)
#         elif option == 2:
#             # 输入登录账户，校验登录账户的信息
#             #  成功: 加载字典里面的信息  失败:重新校验
#             getmoney = input("请输入取款金额：")
#             a.store_money(getmoney)
#         elif option == 3:
#             # 输入登录账户，校验登录账户的信息
#             #  成功: 加载字典里面的信息  失败:重新校验
#             a.draw_money()
#         elif option == 4:
#             break
#     else:
#         print("请输入1-4的数字！")


#注册界面
#每注册一次就实例化一个user对象
#用户名，密码，金额都可以作为user的实例属性进行传入
#全局中定义一个字典 {"root":user1,"szq":user2}
class User():
    def __init__(self, username, passwd, money):
        self.username = username
        self.passwd = passwd
        self.money = money

user_info = {}
while True:
    user = input('please input your name:')
    if user == "exit":
        break
    passwd = input('please input your passwd:')
    money = input('please input init money:')
    if user not in user_info:
        user_info[user] = User(user, passwd, money)
    else:
        print("用户名已存在")
print(user_info)
print(user_info.get('ll').passwd)
